package com.article.dao.impl;

import java.util.List;

import com.article.dao.IArticleDAO;
import com.article.entity.Article;

public class ArticleDAOImpl extends BaseDAOImpl<Article> implements
		IArticleDAO<Article> {
	public static final String TITLE = "title";
	public static final String CONTENT = "content";
	public static final String CLICK_TIMES = "clickTimes";

	public ArticleDAOImpl() {
		super(Article.class);
	}

	public List<Article> findByCategory(int cateId, int start, int limit) {
		String whereJpql = "where o.category.id=?";
		return super.getResultListPage(start, limit, whereJpql, cateId);
	}

	public List<Article> findByTitle(String title, int start, int limit) {
		String whereJpql = "where o." + TITLE + " like '%" + title + "%'";
		return super.getResultListPage(start, limit, whereJpql);
	}

	public Object findCountByCategory(int cateId) {
		String whereJpql = "where o.category.id=?";
		return super.findCount(whereJpql, cateId);
	}

	public Object findCountByTitle(String title) {
		String whereJpql = "where o." + TITLE + " like '%" + title + "%'";
		return super.findCount(whereJpql);
	}

}
